package com.egrid.point.bury.service;

import com.egrid.point.bury.dao.ConfigPropertiesDao;
import com.egrid.point.bury.entity.ConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * ConfigPropertiesService.java
 * Created at 2019-12-27
 * Created by Royal Warmer
 * Copyright (C) 2018 SAIC VOLKSWAGEN, All rights reserved.
 */
@Service
public class ConfigPropertiesService {

    @Autowired
    private ConfigPropertiesDao dao;

    @Transactional
    public String save(ConfigProperties configProperties) {
        configProperties.setCreateDate(new Date());
        ConfigProperties save = this.dao.save(configProperties);
        if(save.getId() != null) {
            return "保存成功";
        }
        return "保存失败";
    }

    public ConfigProperties loadProperties() {
        PageRequest of = PageRequest.of(0, 1);
        List<ConfigProperties> lists = this.dao.findByCreateDate(of);
        return lists.isEmpty() ? null : lists.get(0);
    }

}
